package array;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class test2 {
    public static void main(String[] args) {
        String inputFilePath = "D:\\test\\Hilbert_spatial_keyword_query\\set\\ds1\\query\\query_x\\retail_query_1000_2_10.txt";
        String outputFilePath = "D:\\test\\Hilbert_spatial_keyword_query\\set\\ds1\\query\\query_x\\retail_query_1000_2_10_query.txt";

        try {
            List<String> lines = readLines(inputFilePath);
            List<String> processedLines = processLines(lines);
            writeLines(outputFilePath, processedLines);
            System.out.println("Processed file saved as " + outputFilePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static List<String> readLines(String filePath) throws IOException {
        List<String> lines = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                lines.add(line);
            }
        }
        return lines;
    }

    private static List<String> processLines(List<String> lines) {
        List<String> processedLines = new ArrayList<>();
        for (String line : lines) {
            String[] columns = line.split(",");
            // Skip the first column
            String processedLine = String.join(" ", Arrays.copyOfRange(columns, 1, columns.length));
            processedLines.add(processedLine);
        }
        return processedLines;
    }

    private static void writeLines(String filePath, List<String> lines) throws IOException {
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath))) {
            for (String line : lines) {
                bw.write(line);
                bw.newLine();
            }
        }
    }
}
